﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using EzDesk.Core.Model;

namespace EzDesk.Apps.Model.ProjectModule
{

    [DataContract]
    public enum ProjectStatus
    {
        [EnumMember]
        Ongoing = 0,  // 正在进行中
        [EnumMember]
        Archive = 1,  // 已经完成
    }

    public partial class Project
    {
        [DataMember]
        public ProjectStatus Status
        {
            get { return (ProjectStatus)StatusValue; }
            set { StatusValue = (int)value; }
        }

        [DataMember]
        public IList<SimpleUser> TeamMembers { get; set; }


        [DataMember]
        public SimpleUser Director { get; set; }

        [DataMember]
        public IList<Task> RootTasks
        {
            get { return Task.Where(t => t.ParentTaskId == null).OrderByDescending(t => t.StartOn).ToList(); }
        }

        [DataMember]
        public DateTime CStartOn
        {
            get
            {
                if (StartOn.HasValue) return StartOn.Value;
                if (Task.Count == 0) return DateTime.Today;
                return Task.Min(t => t.StartOn).Value;
            }
            set { StartOn = value; }

        }
    }
}